<?php

/**
**
**/
namespace Common\Common;

use Think\Controller;

class CommonFunction
{
	public static function tabledataToArray($tableData , $rawKey , $prefix=null) {
		$count= count($tableData);
		$return=array();
		for ($i=0 ;$i < $count ; $i++ ){
			$col = $tableData[$i][$rawKey];

			if (strlen(trim($prefix))>0) {
				$return[$prefix.$i]=$col;

			} else {
				$return[]=$col ;
			}

		}
		return $return;

	}
	
	
	
	public static function loadFile($filePath) {
	
		$data = array();
		
		if( !file_exists($filePath) ) return false;
		
		$data    = array_map( "trim", file($filePath) );
		if ( count($data) <= 0 ) return false;
		
		return $data;
	
	}

//20140912 koko.tang create_guid
	public static function guid(){
	    if (function_exists('com_create_guid')){
	        return com_create_guid();
	    }else{
	        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
	        $charid = strtoupper(md5(uniqid(rand(), true)));
	        $hyphen = chr(45);// "-"
	        $uuid = substr($charid, 0, 8).$hyphen
	                .substr($charid, 8, 4).$hyphen
	                .substr($charid,12, 4).$hyphen
	                .substr($charid,16, 4).$hyphen
	                .substr($charid,20,12);
	                
	        return $uuid;
	    }
	}

}